package com.woniu.car.controller;


import com.woniu.car.common.JWTUtil;
import com.woniu.car.common.ResponseEntity;
import com.woniu.car.parameter.AddCarParam;
import com.woniu.car.service.TCarService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 车辆信息表 前端控制器
 * </p>
 *
 * @author zhoubinbin
 * @since 2021-06-21
 */
@RestController
@RequestMapping("/tCar")
@Api(tags = "用户车辆信息新增")
public class TCarController {
    @Resource
    private TCarService carService;
    @ApiOperation(value = "车辆信息新增")
    @PostMapping("addCar")
    public ResponseEntity addCar(@RequestBody AddCarParam addCarParam, HttpServletRequest request) throws Exception {
        return carService.addCar(addCarParam,request);
    }
    //注：测试成功
    @ApiOperation(value = "车辆信息查询")
    @GetMapping("selectCar")
    public ResponseEntity select(HttpServletRequest request) throws Exception {
        String token = request.getHeader("token");
        if (token==null){
            return new ResponseEntity(500,"您当前未登陆,请登陆后进行操作",null);
        }
        String id = JWTUtil.getId(token);
        Integer userId = Integer.valueOf(id);
        return carService.selectCar(userId);
    }
}

